﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Http.Controllers;

namespace Ttifa.WebApiBase.Filters
{
    /// <summary>
    /// 登陆验证
    /// </summary>
    public class LoginAttribute : AuthorizeAttribute
    {
        public override void OnAuthorization(HttpActionContext actionContext)
        {
            var content = actionContext.Request.Properties["MS_HttpContext"] as HttpContextBase;
            var token = content.Request["Token"];
            if (string.IsNullOrEmpty(token))
            {
                HandleUnauthorizedRequest(actionContext);
            }

            //base.OnAuthorization(actionContext);
        }

        protected override void HandleUnauthorizedRequest(HttpActionContext actoinContext)
        {
            actoinContext.Response = ApiResult.Response(ApiStatus.NoLogin, "please sign in and try again");
        }
    }
}